﻿using System;
using System.Windows.Forms;

namespace idataplatform
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (button2.Text == "显示密码")
            {
                button2.Text = "隐藏密码";
                textBox2.PasswordChar = '\0';
            }
            else
            {
                button2.Text = "显示密码";
                textBox2.PasswordChar = '*';
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                label3.Text = "请输入用户名！";
                label3.Visible = true;
            }
            else if (textBox2.Text == "")
            {
                label4.Text = "请输入密码！";
                label4.Visible = true;
            }
            else
            {
                conncls conns = new conncls();

                string seluser = "SELECT upassword FROM users_ipark WHERE uname=\"" + textBox1.Text + "\";";
                string selstatus = "SELECT ustatus FROM users_ipark WHERE uname=\"" + textBox1.Text + "\";";

                if (conns.varStr(seluser) == "")
                {
                    label3.Text = "账号不正确，请联系管理员！";
                    label3.Visible = true;
                }
                else if (conns.varStr(seluser) != textBox2.Text)
                {
                    label4.Text = "密码不正确，请重新输入！";
                    label4.Visible = true;
                }
                else if (conns.varStr(selstatus) != "1")
                {
                    label3.Text = "用户已失效，请联系管理员！";
                    label3.Visible = true;
                }
                else
                {
                    this.DialogResult = DialogResult.OK;
                    this.Dispose();
                    this.Close();
                }
            }
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            label3.Visible = false;
            label4.Visible = false;
            if (e.KeyChar == (char)Keys.Enter)
            {
                textBox2.Focus(); //当在文本框1中检查到回车键时，直接将焦点转入TextBox2
            }
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            label3.Visible = false;
            label4.Visible = false;
            if (e.KeyChar == (char)Keys.Enter)
            {
                button1.Focus(); //当在文本框1中检查到回车键时，直接将焦点转入TextBox2
            }
        }
    }
}
